package com.wannengbang.cloudleader.service.model;

import com.wannengbang.cloudleader.appconst.MethodType;
import com.wannengbang.cloudleader.appconst.URLConst;
import com.wannengbang.cloudleader.base.DataCallBack;
import com.wannengbang.cloudleader.bean.BankListBean;
import com.wannengbang.cloudleader.bean.BaseResponseBean;
import com.wannengbang.cloudleader.bean.CardListBean;
import com.wannengbang.cloudleader.bean.ConsumePlanBean;
import com.wannengbang.cloudleader.bean.PlanDetailsListBean;
import com.wannengbang.cloudleader.bean.PlanListBean;
import com.wannengbang.cloudleader.retorfit_manager.ResponseObserver;
import com.wannengbang.cloudleader.retorfit_manager.RetrofitHelper;
import com.wannengbang.cloudleader.utils.ToastUtil;

import java.util.HashMap;
import java.util.Map;

public class ServiceModelImpl implements IServiceModel {

    @Override
    public void requestRepaymentCardIndex(int page, DataCallBack<CardListBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("page", page);
        params.put("limit", 50);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentCardIndex, params, new ResponseObserver<CardListBean>() {
            @Override
            public void onSuccessful(CardListBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(CardListBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestCardDelete(String id, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentCardDelete, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestCardAdd(String no, String real_name, String bank_id, String due_day, String bill_day, String limit, String expiry_date, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("no", no);
        params.put("real_name", real_name);
        params.put("bank_id", bank_id);
        params.put("due_day", due_day);
        params.put("bill_day", bill_day);
        params.put("limit", limit);
        params.put("expiry_date", expiry_date);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentCardAdd, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestBankList(DataCallBack<BankListBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("page", 1);
        params.put("limit", 50);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentBankList, params, new ResponseObserver<BankListBean>() {
            @Override
            public void onSuccessful(BankListBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BankListBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestCardEdit(String id, String no, String real_name, String bank_id, String due_day, String bill_day, String limit, String expiry_date, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("no", no);
        params.put("real_name", real_name);
        params.put("bank_id", bank_id);
        params.put("due_day", due_day);
        params.put("bill_day", bill_day);
        params.put("limit", limit);
        params.put("expiry_date", expiry_date);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentCardEdit, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestPlanAdd(String card_id, String amount, String consume_count_min, String consume_count_max, String start_date, String end_date, DataCallBack<ConsumePlanBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("card_id", card_id);
        params.put("amount", amount);
        params.put("consume_count_min", consume_count_min);
        params.put("consume_count_max", consume_count_max);
        params.put("start_date", start_date);
        params.put("end_date", end_date);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentGenerate, params, new ResponseObserver<ConsumePlanBean>() {
            @Override
            public void onSuccessful(ConsumePlanBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(ConsumePlanBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestPlanIndex(String card_id, DataCallBack<PlanListBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("card_id", card_id);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentPlanList, params, new ResponseObserver<PlanListBean>() {
            @Override
            public void onSuccessful(PlanListBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(PlanListBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestPlanDetails(String plan_id, DataCallBack<PlanDetailsListBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("plan_id", plan_id);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentDetailIndex, params, new ResponseObserver<PlanDetailsListBean>() {
            @Override
            public void onSuccessful(PlanDetailsListBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(PlanDetailsListBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestPlanComplete(String id, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentDetailComplete, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestPlanRepaymentComplete(String id, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentComplete, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }

    @Override
    public void requestPlanCancel(String id, DataCallBack<BaseResponseBean> callBack) {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        RetrofitHelper.getInstance().request(MethodType.POST, URLConst.RepaymentDetailCancel, params, new ResponseObserver<BaseResponseBean>() {
            @Override
            public void onSuccessful(BaseResponseBean bean, String msg) {
                callBack.onSuccessful(bean);
            }

            @Override
            public void onFailure(BaseResponseBean bean, String msg, String code) {
                ToastUtil.showShort(msg);
            }
        });
    }
}
